package com.cike.productmanager.DBHelper;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.util.Log;
import android.widget.Toast;

public class ActivityCheckInfoContentHandler extends DefaultHandler{

	private static final String TAG = "ActivityCheckInfo_XMLContentHandler";
	private List<ActivityCheckInfo> activityCheckInfos;
	private ActivityCheckInfo activityCheckInfo;
	private String preTag;

	public List<ActivityCheckInfo> getActivityCheckInfos() {
		return activityCheckInfos;
	}
	
	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		
		String data = null;
		
		if(activityCheckInfo != null){
			if(activityCheckInfo.check_id.equals(preTag)){
				data = new String(ch, start, length);
				activityCheckInfo.check_id = data;
			}
			else if (activityCheckInfo.activity_id.equals(preTag)) {
				data = new String(ch, start, length);
				activityCheckInfo.activity_id = data;
			}
			else if (activityCheckInfo.store_code.equals(preTag)) {
				data = new String(ch, start, length);
				activityCheckInfo.store_code = data;
			}
			else if (activityCheckInfo.promostate.equals(preTag)) {
				data = new String(ch, start, length);
				activityCheckInfo.promostate = data;
			}
			else if (activityCheckInfo.promoproductstate.equals(preTag)) {
				data = new String(ch, start, length);
				activityCheckInfo.promoproductstate = data;
			}
			else if (activityCheckInfo.materialstate.equals(preTag)) {
				data = new String(ch, start, length);
				activityCheckInfo.materialstate = data;
			}
			else if (activityCheckInfo.realdisplay.equals(preTag)) {
				data = new String(ch, start, length);
				activityCheckInfo.realdisplay = data;
			}
			else if (activityCheckInfo.isphoto.equals(preTag)) {
				data = new String(ch, start, length);
				activityCheckInfo.isphoto = data;
			}
			else if (activityCheckInfo.level.equals(preTag)) {
				data = new String(ch, start, length);
				activityCheckInfo.level = data;
			}
			else if (activityCheckInfo.state.equals(preTag)) {
				data = new String(ch, start, length);
				activityCheckInfo.state = data;
			}
			else if (activityCheckInfo.remark.equals(preTag)) {
				data = new String(ch, start, length);
				activityCheckInfo.remark = data;
			}
			else if (activityCheckInfo.imagePath.equals(preTag)) {
				data = new String(ch, start, length);
				activityCheckInfo.imagePath = data;
			}
			else if (activityCheckInfo.isOld.equals(preTag)) {
				data = new String(ch, start, length);
				activityCheckInfo.isOld = data;
			}
			
			Log.i(TAG, "�������ݣ�"+new String(ch, start,length));
		}
	}
	
	
	@Override
	public void endDocument() throws SAXException {
		super.endDocument();
		Log.i(TAG, "�ĵ��������");
	}
	
	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		if ("activityCheck".equals(localName)&&activityCheckInfo!=null)
		{
			activityCheckInfos.add(activityCheckInfo);
			activityCheckInfo = null;
		}
		String tag=preTag;
		preTag = null;
		Log.i(tag, localName + "�������");
	}
	
	@Override
	public void startDocument() throws SAXException {
		activityCheckInfos = new ArrayList<ActivityCheckInfo>();
		Log.i(TAG, "��ʼ����...");
	}
	
	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		try {
			if ("activityCheck".equals(localName)) {
				activityCheckInfo = new ActivityCheckInfo();
			}
			preTag = localName;
		} catch (Exception e) {
			// TODO: handle exception
			Toast.makeText(null, "�����¼ʧ��", Toast.LENGTH_SHORT);
		}
	}
}
